package com.mcptt.config.ue.config.sub;

import java.util.List;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.cloudptt.api.product.log.Log;
import com.mcptt.config.ue.config.sub.sub.McpttGroupCall;
import com.mcptt.config.ue.config.sub.sub.PrivateCall;

public class Common {
	
	public static final String Name = "common";
	private static final String Name_Index = "index";
	
	private String index = null;
	private PrivateCall privateCall = null;
	private McpttGroupCall mcpttGroupCall = null;
	
	public void parse(Element elem) throws JDOMException
	{
		if(elem == null)
		{
			return;
		}
		index = elem.getAttributeValue(Name_Index);
		List<Element> list = elem.getChildren();//��ø��ڵ���ӽڵ�  
		for(Element subElem:list) 
		{
			String name = subElem.getName();
			Log.debug(this.getClass(), "name = " + name);
			
			if(name == null
					|| name.length() <= 0)
			{
				return;
			}
			
			if(name.equals(PrivateCall.Name))
			{
				privateCall = new PrivateCall();
				privateCall.parse(subElem);
			}
			else if(name.equals(McpttGroupCall.Name))
			{
				mcpttGroupCall = new McpttGroupCall();
				mcpttGroupCall.parse(subElem);
			}
		}  
	}
	
	public String toString()
	{
		StringBuffer strBuf = new StringBuffer("\r\n");
		strBuf.append("<").append(Name).append(" ").append(Name_Index).append("=\"").append(index).append("\">").append("\r\n");
		
		strBuf.append(privateCall);
		strBuf.append(mcpttGroupCall);
		
		strBuf.append("</").append(Name).append(">").append("\r\n");

		return strBuf.toString();
	}
}
